using System;
using System.Collections.Generic;
using UnityEngine;

public class TriviaQuestions : ScriptableObject
{
	[Serializable]
	public class TriviaQuestion
	{
		public string question;

		public int correctAnswer;

		public List<string> answers = new List<string>();

		public string explanation;
	}

	public List<TriviaQuestion> questions = new List<TriviaQuestion>();

	protected List<TriviaQuestion> randomQuestions = new List<TriviaQuestion>();

	protected int randomQuestionIndex;

	public static TriviaQuestions instance_;

	public static TriviaQuestions instance
	{
		get
		{
			if (instance_ == null)
			{
				instance_ = Resources.Load("TriviaQuestions") as TriviaQuestions;
				instance_.Init();
			}
			return instance_;
		}
	}

	protected void Init()
	{
		CreateNewRandomQuestionList();
	}

	public void CreateNewRandomQuestionList()
	{
		List<TriviaQuestion> list = new List<TriviaQuestion>(questions);
		randomQuestions.Clear();
		while (list.Count > 0)
		{
			int index = UnityEngine.Random.Range(0, list.Count) % list.Count;
			TriviaQuestion item = list[index];
			list[index] = list[list.Count - 1];
			list.RemoveAt(list.Count - 1);
			randomQuestions.Add(item);
		}
	}

	public TriviaQuestion RandomQuestion()
	{
		TriviaQuestion result = randomQuestions[randomQuestionIndex % randomQuestions.Count];
		randomQuestionIndex = (randomQuestionIndex + 1) % randomQuestions.Count;
		return result;
	}
}
